package com.wyq.dao.impl;

import java.util.List;

import com.wyq.bean.Audience;
import com.wyq.bean.Company;
import com.wyq.dao.CompanyDao;
import com.wyq.util.StringUtil;
import com.wyq.util.impl.JDBCDAOSupportImpl;

public class CompanyDaoImpl extends JDBCDAOSupportImpl implements CompanyDao {

	public int deleteCompanyById(String id) throws Exception {
		String sql = "delete from companys where id = " + id;
		int i = this.execupdateBySql(sql);
		return i;
	}

	public List getAllCompany(String showInfoId) throws Exception {
		//String sql = " select * from companys c and c.type="+type;
		String sql = " select c.*,i.showName from companys c left join show_info i on c.show_id = i.id where 1=1";
		if(StringUtil.isNotEmpty(showInfoId)){
			sql += " and show_id = '"+showInfoId+"'";
		}
		sql += " order by RegisterDate desc";
		List list = this.getListMapBySql(sql);
		return list;
	}

	public void saveCompany(Company company) throws Exception {
		this.getHibernateTemplate().save(company);
		
		//return 0;
	}
	
	/**
	 * 验证展商名称是否存在
	 */
	public List companyListByName(String colName,String value,String show_id) throws Exception{
		String sql = "select c.compname from companys c where c."+colName+" = '"+value+"'";
		if(StringUtil.isNotEmpty(show_id)){
			sql += " and show_id = '"+show_id+"'";
		}
		List list = this.getListMapBySql(sql);
		return list;
	}

	public List getCompanyMaxID() throws Exception {
		String sql = "select max(s.id) as id  from companys s";
		List list = this.getListMapBySql(sql);
		
		return list;
	}

	public List getPageCompany(String start, String limit,String showInfoId) throws Exception {
		String sql = "select c.*,s.showName from companys c left join show_info s on c.show_id = s.id where 1=1 ";
		if(StringUtil.isNotEmpty(showInfoId)){
			sql += " and show_id = '"+showInfoId+"'";
		}
		sql += " order by RegisterDate desc limit " + start + "," + limit;
		List list = this.getListMapBySql(sql);
		return list;
	}

	public List getCompanyById(String id) throws Exception {
		String sql = "select * from companys where id = " + id;
		List list = this.getListMapBySql(sql);
		return list;
		//return (Company)this.getHibernateTemplate().get(Company.class, id);
	}

}
